const files = import.meta.glob("./*.vue", { eager: true });

let pages = [];

for (const key in files) {
  const component = files[key].default;
  const name = component.name || key.split("/").pop().replace(".vue", "");

  if (component.meta) {
    pages.push({
      path: `/${name}`,
      name,
      component,
      meta: {
        title: component.meta?.title || name,
        authorityList: component.meta?.authorityList || 0,
        showInMenu: component.meta?.showInMenu !== false,
        icon: component.meta?.icon,
        sort: component.meta?.sort ?? 0,
      },
    });
  }
}

pages = pages.sort((a, b) => a.meta.sort - b.meta.sort);

export const allPages = pages; // 全部页面
export const menuPages = pages.filter(p => p.meta.showInMenu !== false); // 菜单中显示的页面

export default pages; // 保留默认导出
